package com.mall.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.entity.SmsSpikeCommodity;
import com.mall.mapper.SmsSpikeCommodityMapper;
import com.mall.service.SmsSpikeCommodityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SmsSpikeCommodityServiceImpl extends ServiceImpl<SmsSpikeCommodityMapper, SmsSpikeCommodity> implements SmsSpikeCommodityService {

    @Resource
    private SmsSpikeCommodityMapper smsSpikeCommodityMapper;

    @Override
    public SmsSpikeCommodity getById(Integer id) {
        return smsSpikeCommodityMapper.selectById(id);
    }

    @Override
    public List<SmsSpikeCommodity> getAll() {
        return smsSpikeCommodityMapper.selectList(null);
    }

    @Override
    public boolean save(SmsSpikeCommodity smsSpikeCommodity) {
        if(smsSpikeCommodity.getId() == null)
        {
            return smsSpikeCommodityMapper.insert(smsSpikeCommodity) > 0;
        }else{
            return  smsSpikeCommodityMapper.updateById(smsSpikeCommodity) > 0;
        }
    }

    @Override
    public boolean deleteById(Integer id) {
        return smsSpikeCommodityMapper.deleteById(id) > 0;
    }

    @Override
    public List<SmsSpikeCommodity> getBatch(Integer promotionId, Integer sessionId) {
        Map<String, Object> map = new HashMap<>();
        map.put("flash_promotion_id", promotionId);
        map.put("flash_promotion_session_id",sessionId);
        List<SmsSpikeCommodity> list = smsSpikeCommodityMapper.selectByMap(map);
        return list;
    }

    @Override
    public SmsSpikeCommodity getProductRelation(Integer sessionId, Long productId) {
        return smsSpikeCommodityMapper.getProductRelation(sessionId, productId);
    }
}
